home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Id: control.c,v 0.91 1994/02/20 00:53:19 zhao Pre-Release $
- *
- *. This file is part of BIT shareware package. After the two weeks of
- * free evaluation period, you are encouraged (required) to register
- * your copy for a small registration fee, which is $35 for personal use
- * and $50 for commercial, government and institutional use.
- *
- * Copyright(c) 1993, 1994 by T.C. Zhao.
- * All rights reserved.
- *
- * Permission to use, copy, and distribute this software in its entirety
- * for non-commercial purposes is hereby granted, provided that the
- * above shareware and copyright notices and this permission notice
- * appear in all copies and their documentation.
- *
- * This software may be modified for your own use, but modified versions
- * may not be distributed without prior consent of the author.
- *
- * This software is provided "as is" without expressed or implied
- * warranty of any kind.
- *
- *.
- *
- * Main forms. FilePanel and ControlPanel.
- *
- */
- #if !defined(lint) && defined(F_ID)
- char *id_cntl = "$Id: control.c,v 0.91 1994/02/20 00:53:19 zhao Pre-Release $";
- #endif
-
- #include "bit.h"
- #include "extern.h"
-
- static void create_forms(void);
- static void up_dn_cb(FL_OBJECT *, long);
- static FL_FORM *cntl, *info;
- static FL_OBJECT *etitle, *infog;
-
- /**************************************************************
- * Where the control window should be. Maybe called by init
- *************************************************************/
- void
- set_control_window_position(int x, int y)
- {
- create_forms();
- cntl->x = x;
- cntl->y = y;
- }
-
- /**************************************************************
- * map and show control window
- ***************************************************************/
- long
- show_control_window(int x, int y, int w, int h, int bd)
- {
- int place;
-
- create_forms();
- if (cntl->visible)
- return cntl->window;
-
- place = FL_PLACE_POSITION;
-
- if (w > 0 && h > 0)
- {
- prefposition(x, x + w - 1, y, y + h - 1);
- place = FL_PLACE_FREE;
- }
- else if (x >= 0 || y >= 0)
- {
- fl_set_form_position(cntl, x, y);
- }
-
- bit_show_form(cntl, place, bd, "BITControl");
- set_cursor(cntl->window, CUR_HAND);
- set_default_cursor(cntl->window, CUR_HAND);
- return cntl->window;
- }
-
- /******************************************************
- * unmap control wndows
- ******************************************************/
- void
- hide_control_window(void)
- {
- create_forms();
- if (cntl->visible)
- bit_hide_form(cntl);
- }
-
- /********************************************************/
- long
- get_control_wid(void)
- {
- create_forms();
- return cntl->window;
- }
-
- /*** Save current control window position to file *****/
- void
- write_control_window_position(FILE * fp)
- {
- fprintf(fp, "%d %d # Lower-left corener of ControlPanel\n",
- (int) cntl->x, (int) cntl->y);
- }
-
-
- /*********************************************************
- * Editing groups
- * Editing is defined as any transformation that changes one
- * or more field in the image structure.
- *******************************************************{**/
-
- #define MAXSHOWN 15
- static FL_OBJECT *bedit[MAXSHOWN + 1];
- static FL_OBJECT *edgrp, *pgrp, *cgrp, *mgrp, *exgrp;
- static int maxshown;
-
- /************************************************************
- * Ordinarily all editing function blocks double entry and that
- * is done via deactivation of groups/forms. In some cases, we
- * might want to have a particular group active
- *************************************************************/
- enum exclusions_
- {
- EX_NONE = 0, EX_PAN = 1, EX_EDIT = 2,
- EX_MISC = 1 << 2, EX_CONV = 1 << 3, EX_EXB = 1 << 4
- };
-
- /****** All editing functions takes the following form **** */
- typedef int (*Igfptr) (IPTR);
-
- typedef struct
- {
- const char *name; /* editing function name */
- Igfptr edit; /* the function itself */
- int bcolor; /* button color when pressed */
- int disp; /* if demands a display */
- int exclude; /* deactivate edit panel */
- }
- Edit_t;
-
- extern int do_ibrowse(IPTR);
-
- /*
- * main structure. If more editing functions than that can be shown, a
- * flip button will appear.
- */
-
- static Edit_t edit[] =
- {
- {"Crop", do_crop, FL_YELLOW, 0, EX_PAN},
- {"Cut&Paste", do_cut_paste, FL_YELLOW, 1, EX_PAN},
- {"Text", do_text, FL_GREEN, 0, EX_PAN},
- {"Marking", img_marking, FL_GREEN, 1, EX_PAN},
- {"Rotate", do_rotate, FL_YELLOW, 1, EX_NONE},
- {"Scale", do_scale, FL_YELLOW, 1, EX_NONE},
- {"PixTran", do_coledit, FL_GREEN, 0, EX_PAN},
- {"PixelEdit", pixel_edit, FL_YELLOW, 0, EX_NONE},
- {"Merge", do_merge, FL_YELLOW, 0, EX_NONE},
- {"Paint", img_paint, FL_YELLOW, 1, EX_PAN},
- {"EditMap", do_editmap, FL_YELLOW, 0, EX_NONE},
- {"Smooth", img_smooth, FL_RED, 0, EX_PAN},
- {"Sharpen", do_sharpen, FL_RED, 1, EX_NONE},
- {"MedianF", do_medianf, FL_YELLOW, 0, EX_NONE},
- {"ImgDiff", img_diff, FL_RED, 1, EX_NONE},
- {"Edge", img_edge, FL_RED, 1, EX_NONE},
- {"Enhance", img_enhance, FL_RED, 1, EX_NONE},
- {"Measure", img_measure, FL_GREEN, 0, EX_NONE},
- {"Histogram", img_show_histogram, FL_YELLOW, 0, EX_NONE},
- {"Normalize", img_norm, FL_RED, 1, EX_NONE},
- #if 0
- {"FFT", img_fft, FL_YELLOW, 0, EX_NONE}
- {"SimpleCP", do_scp, FL_YELLOW, 0, 1},
- {"HistoSpec", do_hspec, FL_YELLOW, 0, 1},
- #endif
- };
-
- static int totaledit = sizeof(edit) / sizeof(edit[0]);
- static int offset;
-
- /**************************************************************
- * Selectively leave some editing group active
- *************************************************************/
- static void
- exclude_groups(int exclude, void (*what) (FL_OBJECT *))
- {
- if (!(exclude & EX_EDIT))
- what(edgrp);
-
- if (!(exclude & EX_EXB))
- what(exgrp);
-
- if (!(exclude & EX_PAN))
- what(pgrp);
-
- if (!(exclude & EX_MISC))
- what(mgrp);
-
- if (!(exclude & EX_CONV))
- what(cgrp);
- }
-
- /***************************************************************
- * When an edit button is pressed, this routine is activated
- **************************************************************/
-
- /* ARGSUSED */
- static void
- edit_cb(FL_OBJECT * obj, long i)
- {
- static int inedit;
- Edit_t *cedit = edit + i; /* curent editing structure */
- int is_ci;
-
- /*
- * All editing functions are non re-entrant by nature, must not allow
- * double entry. Further, must have a valid image to edit and make
- * special provision for paint where we can create images on the fly
- */
-
- if (inedit ||
- (cedit->edit != img_paint && !image_ready(imgptr, cedit->name)))
- return;
-
- inedit = 1;
-
- /* block double entry with provision for exclusions */
-
- exclude_groups(cedit->exclude, fl_deactivate_object);
-
- /* remember current image type */
- is_ci = IS_CI(imgptr);
-
- if (cedit->edit(imgptr) >= 0)
- {
- /* if image type change, do it for text and sgf as well */
- if (!is_ci && IS_CI(imgptr))
- {
- text_to_cmap();
- sgf_to_cmap();
- }
-
- /* if requires re-display, do it here */
- if (cedit->disp)
- imgptr->io->display(imgptr, double_buf ? -1 : 4, 1);
-
- update_image_info(imgptr);
- }
-
- exclude_groups(cedit->exclude, fl_activate_object);
-
- inedit = 0;
- }
-
- /***** walks up and down the editing functions ******/
- /* ARGSUSED */
- static void
- up_dn_cb(FL_OBJECT * obj, long dir)
- {
- int i;
-
- fl_freeze_form(cntl);
-
- if ((offset + maxshown) <= totaledit)
- offset += maxshown;
- else if (offset >= maxshown)
- offset -= maxshown;
-
- for (i = 0; i < maxshown && i + offset < totaledit; i++)
- {
- fl_set_object_label(bedit[i], edit[i + offset].name);
- fl_show_object(bedit[i]);
- fl_set_call_back(bedit[i], edit_cb, i + offset);
- }
-
- for (; i < maxshown; i++)
- fl_hide_object_only(bedit[i]);
- fl_unfreeze_form(cntl);
- }
-
-
- /* End of Ending group } */
-
-
- /****************************************************************
- * Type conversion group
- *************************************************************{**/
- typedef struct
- {
- const char *lab; /* type name for the image */
- IMG_TYPE type; /* internal name */
- }
- C_t;
-
- /* maybe stick a quant some where */
- static C_t ct[] =
- {
- {"Color(RGB)", T_RGBA},
- {"Color(Map)", T_CMAP},
- {"Gray(Map)", T_GMAP},
- {"Gray(RGB)", T_GRAY},
- {"B&W", T_BW}
- };
-
- static int totalct = sizeof(ct) / sizeof(ct[0]);
-
- /* ARGSUSED */
- static void
- type_cb(FL_OBJECT * obj, long j)
- {
- C_t *cct = ct + j; /* current conversion structure */
-
- show_busy("Converting ...");
- if (img_convert_type(imgptr, cct->type) >= 0)
- {
- /* force the type to be the requested */
- imgptr->type = cct->type;
- if (cct->type == T_GRAY)
- {
- text_to_gray();
- sgf_to_gray();
- }
- else if (IS_CI(imgptr))
- {
- text_to_cmap();
- sgf_to_cmap();
- }
- update_image_info(imgptr);
- imgptr->io->display(imgptr, 0, 0);
- }
- end_busy();
- }
-
- /* End of type conversion group } */
-
- /***************************************************************
- * External pipes and filters
- **********************************************************{****/
-
- #define EXT_CONVOLV 1
- #define EXT_FILTER 2
-
- /* ARGSUSED */
- static void
- ext_cb(FL_OBJECT * obj, long what)
- {
- if (!image_ready(imgptr, "ExtBinding"))
- return;
-
- ((what == EXT_CONVOLV) ? do_ext_convolv : do_ext_filter) (imgptr);
- }
-
- /* End of external pipes } */
-
- /************************************************************
- * Image panning
- ********************************************************{**/
-
- static FL_OBJECT *pspeed;
-
- int
- get_pan_speed(void)
- {
- return fl_get_counter_value(pspeed);
- }
-
- /* ARGSUSED */
- static void
- pan_cb(FL_OBJECT * ob, long dir)
- {
- image_pan(imgptr, dir, get_pan_speed());
- }
-
- /******************* End of pan **********************}**/
-
- /************************************************************
- * Misc control group
- *********************************************************{**/
- typedef enum
- {
- MISC_HIDE,
- MISC_ZOOM,
- MISC_INFO,
- MISC_SYSMAP,
- MISC_DELETE
- } menum_t;
-
- struct tmp_
- {
- const char *lab;
- const char *scut;
- int bcol;
- menum_t cbi;
- };
-
- static struct tmp_ misccn[] =
- {
- {"Magnify", "Zz", FL_GREEN, MISC_ZOOM},
- {"HideC", "Cc", FL_YELLOW, MISC_HIDE},
- {"ToggleF", "Ff", FL_YELLOW, MISC_INFO},
- {"SysMap", "Mm", FL_YELLOW, MISC_SYSMAP},
- {"Delete", "Dd", FL_RED, MISC_DELETE}
- };
-
- static int totalmisc = sizeof(misccn) / sizeof(struct tmp_);
-
- /******* Remove a file from disk ************/
- static void
- delete_file(void)
- {
- char *ptmp = 0;
- int goahead;
-
-
- goahead = (always_delete || yes_no("DelFromDiskConfirm",
- ptmp = vstrcat("Remove ", imgptr->ifile, " from disk"),
- "Are You Sure ?", 0));
-
- if (goahead)
- {
- if (remove(imgptr->ifile))
- {
- M_warn("Delete", "Delete %s failed", imgptr->ifile);
- }
- else
- {
- /* no sense keeping it on the list */
- delete_from_list1(imgptr->ifile);
-
- /* also remove its associated thumnails */
- if (auto_remove_thumbnail)
- del_thumbnail(0, imgptr->ifile);
- }
-
- if (ptmp)
- free_vstrcat(ptmp);
- }
- }
-
- /*********** Misc function handler *********************/
- #include "dmalloc.h" /* for free */
- /* ARGSUSED */
- static void
- misc_cb(FL_OBJECT * ob, long j)
- {
- switch (j)
- {
- case MISC_HIDE: /* hide control form */
- bit_hide_form(cntl);
- break;
-
- case MISC_ZOOM: /* actvete zooming */
- image_zoom(imgptr);
- break;
-
- case MISC_INFO: /* toggle info panel */
- if (info->visible)
- hide_info_window();
- else
- show_info_window(-1, -1, -1, -1, 1);
- break;
-
- case MISC_SYSMAP: /* restore system colormap */
- set_sysmap(0);
- break;
-
- case MISC_DELETE:
- if (imgptr && imgptr->ifile[0])
- delete_file();
- break;
- }
- }
- /*********** End of misc control } ***********/
-
-
- /*******************************************************************
- * show more info about current state of the program
- *******************************************************************/
-
- /**** add one more line ****/
- void
- showit(const char *s)
- {
- char more[150];
- (void) strncat(strcpy(more, "@f"), s, sizeof(more) - 1);
- add_to_help(more);
- }
-
- #define YN(a) (a) ? "Yes":"No"
-
- /* ARGSUSED */
- static void
- show_image_info(FL_OBJECT * obj, long nouse)
- {
- char line[120];
- char gcdir[300];
- int i, k;
- const char *fmt2 = "%11s %s";
-
- set_help_title("CurrentInfo");
- showit(" ");
- sprintf(line, "@b@c ImageInfo");
- showit(line);
-
- if (!imgptr || !imgptr->io)
- {
- showit("No image");
- goto otherinfo;
- }
-
- sprintf(line, fmt2, "Filename", imgptr->ifile);
- showit(line);
- sprintf(line, fmt2, "Format", imgptr->io->info);
- showit(line);
- sprintf(line, "%11s: %s(%s)", "Type", IS_CI(imgptr) ? "Cmap" : "RGB",
- IS_GRAY(imgptr) ? "Gray" : "Color");
- showit(line);
- sprintf(line, "%11s: %d X %d", "Size", imgptr->w, imgptr->h);
- showit(line);
-
- if (imgptr->ok)
- {
- sprintf(line, "%11s: (%d,%d)", "Location", imgptr->xi, imgptr->yi);
- showit(line);
- }
-
- sprintf(line, "%11s: %d bytes", "PixelSize", imgptr->esize);
- showit(line);
- sprintf(line, "%11s: %lu bytes", "RasterSize", imgptr->size);
- showit(line);
- if (imgptr->cmap && imgptr->cmap->colors)
- {
- sprintf(line, fmt2, "Colormap", "Yes");
- showit(line);
- sprintf(line, "%11s: %d", "Colors", imgptr->cmap->colors);
- showit(line);
- sprintf(line, fmt2, "Packed", YN(imgptr->cmap->packed));
- showit(line);
- }
- else
- {
- sprintf(line, fmt2, "Colormap", "No");
- showit(line);
- }
- sprintf(line, fmt2, "Status", imgptr->ok ? "Ready" : "Not Ready");
- showit(line);
-
- /*
- * All paths
- */
- otherinfo:
- showit("@b@c FileInfo");
- getcwd(gcdir, 288);
- sprintf(line, fmt2, "CurrentDir:", gcdir);
- showit(line);
- sprintf(line, fmt2, "BitDir:", bitpath);
- showit(line);
- sprintf(line, fmt2, "HelpDir:", helppath);
- showit(line);
- showit(" ");
-
- /*
- * misc info about program
- */
- showit("@b@c MiscInfo");
- sprintf(line, "%11s: %d X %d", "ScreenSize",
- (int) getgdesc(GD_XPMAX), (int) getgdesc(GD_YPMAX));
- showit(line);
-
- sprintf(line, "%11s: %d\t%12s: %d", "ScreenDPI", get_scr_dpi(),
- "DefaultMaps", get_number_of_defmaps());
- showit(line);
- sprintf(line, "%11s: %dK\t%12s: %dK ", "FontCache",
- get_fm_cache(), "Used", get_fm_cacheused());
- showit(line);
- sprintf(line, "%11s: %ld", "MainWid", win_id);
- showit(line);
- sprintf(line, "%15s: %ldX%ld", "Size", win_w, win_h);
- showit(line);
- sprintf(line, "%15s: (%ld,%ld)", "Origin", win_xo, win_yo);
- showit(line);
- sprintf(line, "%11s: %ld\t%11s:%ld", "InfoWid", get_info_wid(),
- "ControlWid", get_control_wid());
- showit(line);
- sprintf(line, "%11s: %ld", "CurrentWid", winget());
- showit(line);
- sprintf(line, "%11s: %d", "WMhandler", total_wm_handler());
- showit(line);
- sprintf(line, "%11s: %d", "GLQhandler", total_GLQ_handler());
- showit(line);
- sprintf(line, "%11s: %s", "FormDblbuf", YN(fl_doublebuf));
- showit(line);
- /*
- * C & P info
- */
- showit(" ");
- showit("@b@c CutPasteInfo");
- if ((k = no_of_cut_paste_buffers()) > 0)
- {
- for (i = 0; i < k; i++)
- {
- sprintf(line, "%s", cut_paste_buffer_name(i));
- showit(line);
- }
- }
- else
- showit("@c None");
- /*
- * Text info
- */
- showit(" ");
- showit("@b@c Text Info");
- if ((k = number_of_text()) > 0)
- {
- int r, g, b;
- sprintf(line, "@c Total %d strings", k);
- showit(line);
- for (i = 0; i < k; i++)
- {
- sprintf(line, "@s%d: %s ", i + 1, get_text_string(i));
- showit(line);
- get_text_color(i, &r, &g, &b);
- sprintf(line, " Fontname: %s, size=%.1f",
- get_text_fontname(i), get_text_fontsize(i));
- showit(line);
- sprintf(line, " Color: r=%d g=%d b=%d", r, g, b);
- showit(line);
- get_text_location(i, &r, &g);
- sprintf(line, " Location: (%d %d) %s", r, g,
- (get_text_rotation(i) > 0.1) ? "Rotated" : "");
- showit(line);
- }
- }
- else
- showit("@c None");
- /*
- * Simple geometric figures info
- */
- showit(" ");
- showit("@b@c Marking Info");
- if ((k = number_of_sgf()) > 0)
- {
- int x, y, t, w, h, r, g, b, a;
- sprintf(line, "@c Total %d sgfs", k);
- showit(line);
- for (i = 0; i < k; i++)
- {
- sprintf(line, "%d: %s", i + 1, sgf_name(i));
- showit(line);
- get_sgf_info(i, &x, &y, &w, &h, &t, &b, &a);
- sprintf(line,
- " Where: (%d,%d) Size: (%d,%d) Lwidth:%d Rot:%d",
- x, y, w, h, t, a);
- showit(line);
- get_sgf_color(i, &r, &g, &b);
- sprintf(line, " Color: R=%d G=%d B=%d", r, g, b);
- showit(line);
- }
- }
- else
- showit("@c None");
- show_help(0, 0, -1, -1, 0);
- }
-
- /* ARGSUSED */
- static void
- special_cb(FL_OBJECT * ob, long q)
- {
- if (imgptr->ok <= 0)
- return;
- if (imgptr->io && imgptr->io->special)
- imgptr->io->special(imgptr);
- else
- show_image_info(ob, q);
- }
-
- /* End of editing forms */
-
- /************************************************************************
- *
- * Informational forms and also some control
- *
- ************************************************************************/
- static FL_OBJECT *freport[5], *pslider, *ptext;
- static FL_OBJECT *mreport[4], *mrptg;
-
- /*
- * Global functions to manipulate the info panel
- */
- long
- get_info_wid(void)
- {
- create_forms();
- return info->window;
- }
-
- void
- hide_info_window(void)
- {
- if (info->visible)
- bit_hide_form(info);
- }
-
- /**************************************************************
- * Where to place info window. May be called by init
- *************************************************************/
- void
- set_info_window_position(int x, int y)
- {
- create_forms();
- info->x = x;
- info->y = y;
- }
-
- long
- show_info_window(int x, int y, int w, int h, int b)
- {
- int i, place;
-
- create_forms();
-
- if (info->visible)
- return info->window;
-
- place = FL_PLACE_POSITION;
- if (w > 0 && h > 0)
- {
- prefposition(x, x + w - 1, y, y + h - 1);
- place = FL_PLACE_FREE;
- }
- else if (x >= 0 || y >= 0)
- {
- fl_set_form_position(info, x, y);
- }
- /* need to hide all */
- fl_hide_object(pslider);
- fl_hide_object(ptext);
-
- for (i = 0; i < 4; i++)
- fl_hide_object(mreport[i]);
-
- bit_show_form(info, place, b, "File");
- return info->window;
- }
-
- void
- write_info_window_position(FILE * fp)
- {
- fprintf(fp, "%d %d # Lower-left corener of FilePanel\n",
- (int) info->x, (int) info->y);
- }
-
- /* make info window always active */
- void
- deactivate_all_forms(void)
- {
- create_forms();
- fl_deactivate_all_forms();
- fl_activate_form(info);
- }
-
-
- void
- update_color_info(IPTR im)
- {
- char lstr[70];
- const char *p = "";
-
- if (IS_CI(im))
- {
- p = IS_BW(im) ? "B&W" : (IS_GRAY(im) ? "Graymap" : "Map");
- if (im->cmap->ucolors && im->cmap->ucolors < im->cmap->colors)
- sprintf(lstr, "%s:%d(%d uniq)", p, im->cmap->colors,
- im->cmap->ucolors);
- else
- sprintf(lstr, "%s:%d", p, im->cmap->colors);
- }
- else if (IS_CPACK(im))
- {
- p = IS_GRAY(im) ? "Grayscale" : "RGB";
- if (im->colors > 0)
- sprintf(lstr, "%s:%d", p, im->colors);
- else
- strcpy(lstr, p);
- }
- else
- {
- Bark("UpdateInfo", "Should not happen");
- clean_up();
- }
- fl_set_object_label(freport[3], lstr);
- }
-
- /****** show current image info, faking jpeg ********/
- void
- update_size_info(int w, int h)
- {
- char lstr[100];
-
- /* special for w==1 and h==1, meaning dimension not known yet */
- if ((w == 1 && h == 1) || report_level < 0)
- return;
- sprintf(lstr, "%dX%d", w, h);
- fl_set_object_label(freport[2], lstr);
- }
-
- void
- update_filename(char *f)
- {
- fl_set_object_label(freport[0], f ? f : "None");
- }
-
- void
- update_format_info(IPTR im)
- {
- fl_set_object_label(freport[1], im->info);
- }
-
-
- void
- update_misc_info(IPTR im)
- {
- fl_set_object_label(freport[4], im->info);
- }
-
- /***** special hack: if img->esize == img->w == img->h == 1, do nothing ***/
- void
- update_image_info(IPTR im)
- {
- char brief[100];
-
- if (!im)
- {
- fl_freeze_form(info);
- fl_set_object_label(freport[0], "None");
- fl_set_object_label(freport[1], " ");
- fl_set_object_label(freport[2], " ");
- fl_set_object_label(freport[3], " ");
- fl_set_object_label(freport[4], " ");
- fl_unfreeze_form(info);
- fl_set_object_label(etitle, "None");
- return;
- }
-
- if ((im->h == 1 && im->w == 1) || report_level < 0)
- return;
-
- fl_freeze_form(info);
-
- if (strlen(im->ifile) > 22)
- {
- Strncpy(brief, im->ifile, 22);
- fl_set_object_label(freport[0], brief);
- }
- else
- fl_set_object_label(freport[0], im->ifile);
-
- fl_set_object_label(freport[1], im->info);
- update_size_info(im->w, im->h);
- update_color_info(im);
- fl_set_object_label(freport[4], im->misc);
- fl_unfreeze_form(info);
-
- /* generate a brief info for edit form */
- sprintf(brief, "%s (%s %dX%d %s)", im->ifile, im->key,
- im->w, im->h, IS_GRAY(im) ? "Gray" : (IS_BW(im) ? "BW" : "Color"));
- fl_set_object_label(etitle, brief);
- }
-
- /*********** Misc info *****************/
- void
- show_rect_size(int w, int h)
- {
- char lstr[100];
-
- if (!info->visible)
- return;
- sprintf(lstr, "Size:\t%dX%d", w, h);
- fl_set_object_label(mreport[0], lstr);
- if (!mreport[0]->visible)
- fl_show_object(mreport[0]);
- }
-
- void
- hide_rect_size(void)
- {
- if (!info->visible || !mreport[0]->visible)
- return;
- fl_hide_object_only(mreport[0]);
- }
-
- void
- show_rect_ori(int x, int y)
- {
- char lstr[100];
-
- if (!info->visible)
- return;
- sprintf(lstr, "Ori:\t(%d,%d)", x, y);
- fl_set_object_label(mreport[1], lstr);
- if (!mreport[1]->visible)
- fl_show_object(mreport[1]);
- }
-
- void
- show_rect_all(int x, int y, int w, int h, int dotheta)
- {
- float theta;
- char treport[10];
-
- if (!info->visible)
- return;
-
- fl_freeze_form(info);
- show_rect_ori(x, y);
- show_rect_size(w, h);
- if (dotheta)
- {
- get_theta(w, h, &theta);
- sprintf(treport, "Theta=%.2f", theta);
- show_misc_info(treport);
- }
- fl_unfreeze_form(info);
- }
-
- /********* Hide alll misc. infomation ***************/
- void
- hide_rect_all(void)
- {
- int i;
-
- if (!info->visible)
- return;
- fl_freeze_form(info);
- for (i = 0; i < 4; i++)
- fl_hide_object_only(mreport[i]);
- fl_unfreeze_form(info);
- }
-
- void
- show_misc_info2(const char *s)
- {
- if (!info->visible)
- return;
- fl_set_object_label(mreport[2], s);
- if (!mreport[2]->visible)
- fl_show_object(mreport[2]);
- }
-
- void
- hide_misc_info2(void)
- {
- fl_hide_object_only(mreport[2]);
- }
-
- void
- show_misc_info(const char *s)
- {
- if (!info->visible)
- return;
- fl_set_object_label(mreport[3], s);
- if (!mreport[3]->visible)
- fl_show_object(mreport[3]);
- }
-
- void
- show_rect_speed(int sp)
- {
- char lstr[100];
-
- if (!info->visible)
- return;
- sprintf(lstr, "Speed:%d", sp);
- show_misc_info2(lstr);
- }
-
- /* whatever passed is always relative to window */
- void
- show_mouse_position(int x, int y)
- {
- char loc[20];
-
- if (report_mouse == 0)
- return;
-
- if (report_mouse == 1 || !imgptr)
- { /* relative to window */
- sprintf(loc, "(%d %d)", x, y);
- }
- else
- {
- sprintf(loc, "(%d %d)", x - imgptr->xi, y - imgptr->yi);
- }
- show_misc_info2(loc);
- }
-
- void
- hide_mouse_position(void)
- {
- hide_misc_info2();
- }
-
- void
- hide_misc_info(void)
- {
- fl_hide_object_only(mreport[3]);
- }
-
-
-
- /********************************************************************
- * File IO group
- *******************************************************************{*/
- enum nouse
- {
- F_CONFIG, F_LOAD, F_WRITE, F_QUIT
- };
-
- typedef struct
- {
- enum nouse cbi; /* call back parameter */
- const char *lab; /* button label */
- const char *scut; /* shortcuts */
- }
- Fio_t;
-
- static Fio_t fiob[] =
- {
- {F_CONFIG, "Setup", "sS"},
- {F_LOAD, "Load", "Ll"},
- {F_WRITE, "Write", "Ww"},
- {F_QUIT, "Quit", "^QQq"}
- };
-
- static int totalfio = sizeof(fiob) / sizeof(fiob[0]);
- static FL_OBJECT *iogroup;
-
- /*******************************************************************
- * Handle File IO requests.
- *
- * Since load/write/setup uses some command area, they should not
- * be active simultanousely. need fix individual routine before
- * remove the blocking here
- *******************************************************************/
-
- /*ARGSUSED*/
- static void
- file_cb(FL_OBJECT * ob, long what)
- {
- if (what == F_QUIT)
- {
- if (yes_no("QUIT", "Are you sure ?", "", 0))
- clean_up();
- return;
- }
-
- fl_deactivate_object(iogroup);
-
- switch (what)
- {
- case F_CONFIG:
- config_sys();
- break;
-
- case F_LOAD:
- load_files();
- break;
-
- case F_WRITE:
- do_dump(imgptr);
- break;
- }
-
- fl_activate_object(iogroup);
- }
-
- /***********************************************************************
- * Print a breif help messages in a browser with version info
- **********************************************************************/
- /* ARGSUSED */
- void
- version_cb(FL_OBJECT * r, long what)
- {
- const char **p = p_version;
- char lstr[100];
- int i = 1;
-
- load_help("main.hlp", "ProgramInfo");
- insert_help(" ", 1);
-
- do
- {
- sprintf(lstr, "@C1@c@b%s", rm_rcs_kw(*p));
- ++i;
- insert_help(lstr, i);
- }
- while (*++p);
-
- /* list all supported formats */
- enumerate_formats(showit);
- show_help(0, 0, -1, -1, 0);
- }
-
- /******************************************************************
- * END OF FILE IO GROUP
- *****************************************************************}*/
-
-
- /* misc controls on info form */
- typedef enum
- {
- IMISC_BROWSE,
- IMISC_REPAINT,
- IMISC_EDIT
- } imenum_t;
-
- struct itmp_
- {
- const char *lab; /* label for button */
- imenum_t m; /* index */
- int c; /* color when button down */
- const char *scuts; /* keyboard short cuts */
- };
-
- static struct itmp_ imisccn[] =
- {
- {"Ibrowser", IMISC_BROWSE, FL_YELLOW, "iI"},
- {"Repaint", IMISC_REPAINT, FL_GREEN, "rR"},
- {"Edit", IMISC_EDIT, FL_RED, "Ee"}
- };
-
- static int totalimisc = sizeof(imisccn) / sizeof(imisccn[0]);
-
- /******************************************************************
- * Handle misc. requests
- ******************************************************************/
- /* ARGSUSED */
- static void
- imisc_cb(FL_OBJECT * ob, long j)
- {
-
- switch (imisccn[j].m)
- {
- case IMISC_EDIT:
- if (!cntl->visible)
- show_control_window(-1, -1, -1, -1, 0);
- else
- hide_control_window();
- break;
-
- case IMISC_BROWSE:
- ibrowse_dir((char *) 0);
- break;
-
- case IMISC_REPAINT:
- do_repaint(imgptr);
- break;
- }
- }
-
- /********************** progress report etc *************************/
-
- #ifndef NO_TIMING
- #include <time.h>
- static clock_t lasttime;
- #endif
-
- void
- remove_progress_report(void)
- {
- char pp[20];
-
- if (report_level >= 0)
- remove_rotate_cursor();
-
- #ifndef NO_TIMING
- lasttime = clock() - lasttime;
- lasttime /= 1000;
- sprintf(pp, "%ld msec", (long) lasttime);
- #endif
-
- /*
- * following line makes sure that multiple call of this routine will not
- * screwup the timing
- */
- if (report_level > 0 && !pslider->visible) /* already called */
- return;
-
- if (pslider->visible)
- fl_hide_object_only(pslider);
- if (ptext->visible)
- fl_hide_object_only(ptext);
-
- #ifndef NO_TIMING
- show_misc_info(pp);
- #endif
-
- }
-
- static float denorm = -1;
- static int adjfactor;
-
- long
- progress_report(const char *s, long max_i)
- {
- long every;
-
- /*
- * if not requesting progress report, set frequency to something large,
- * but can't be max_i 'cause we still want to service the emergency_Q
- * events with upate_progress_report
- */
-
- if (report_level < 0)
- {
- if (pslider->visible)
- remove_progress_report();
- return (max_i / 3);
- }
-
- rotate_cursor();
- denorm = max_i - 1;
-
- /* no reporting is desired */
- if (report_level <= 0)
- {
- if (pslider->visible)
- remove_progress_report();
- }
- else
- {
- fl_set_object_label(ptext, s);
- fl_set_slider_value(pslider, 0.0);
- hide_misc_info(); /* this will make timing report nicer */
- if (!pslider->visible)
- {
- fl_show_object(pslider);
- fl_show_object(ptext);
- }
- }
-
- #ifndef NO_TIMING
- lasttime = clock();
- #endif
-
- /* if no percentage report, let cursor rotate every 10 percent */
-
- every = (denorm * 0.01 * (report_level ? percent_report : 10));
-
- /*
- * if image is large, say has a hight more than 1000, half the frequency.
- * Note that sometimes max_i is in bytes, need to take care of that
- */
-
- if (max_i > 1000 && max_i < 100000L)
- {
- every /= (adjfactor = 2);
- }
- else
- adjfactor = 1;
- return every < 1 ? 1 : every;
- }
-
- /*
- * we have to allow this routine to be called even if we don't what to show
- * the slider because we need to check Q-events periodically
- */
- void
- update_progress_report(long j)
- {
- int cheat, tpercent;
-
- check_emergency();
-
- if (report_level <= 0)
- {
- if (report_level == 0)
- rotate_cursor();
- return;
- }
-
- rotate_cursor();
-
- tpercent = percent_report / adjfactor;
-
- /*
- * due to the discret nature of scan line, reported percentage can be off
- * by a few percent. Corrected it here
- */
-
- cheat = (j * 100.0 / denorm + 0.02);
- if (cheat % percent_report)
- {
- cheat = ((cheat + 2) / tpercent) * tpercent;
- }
- if (cheat > 100)
- cheat = 100;
- fl_set_slider_value(pslider, 0.01 * cheat);
- }
-
- static void
- create_form_cntl(void)
- {
- FL_OBJECT *obj;
- int i, j, ii;
- float x, x0, y, dx, dy;
- char lp[20];
-
- cntl = fl_bgn_form(FL_NO_BOX, 345.0, 370.0);
- obj = fl_add_box(FL_UP_BOX, 0.0, 0.0, 345.0, 370.0, "");
- fl_set_object_color(obj, 12, 47);
-
- /* help buttun */
- obj = fl_add_button(FL_HIDDEN_BUTTON, 0.0, 0.0, 345.0, 370.0, "");
- fl_set_call_back(obj, help_cb, HELP_CNTL);
-
- /* editing group */
- edgrp = fl_bgn_group();
- obj = fl_add_box(FL_SHADOW_BOX, 10.0, 10.0, 220.0, 180.0, "");
- fl_set_object_color(obj, 9, 47);
-
- y = 125;
- x = x0 = 15;
- dx = 70;
- dy = 25;
- ii = Min(totaledit, MAXSHOWN - 2);
-
- for (dx = 70, dy = 25, i = j = 0; i < ii; i += 3, y -= dy, x = x0)
- {
- j = i;
- bedit[j] = fl_add_button(FL_NB, x, y, dx, dy, edit[j].name);
- fl_set_object_lsize(bedit[j], 10.0);
- fl_set_object_color(bedit[j], FL_MAGIC1, edit[j].bcolor);
- fl_set_call_back(bedit[j], edit_cb, j);
- x += dx;
- j++;
-
- if (j < totaledit)
- {
- bedit[j] = fl_add_button(FL_NB, x, y, dx, dy, edit[j].name);
- fl_set_object_lsize(bedit[j], 10.0);
- fl_set_object_color(bedit[j], FL_MAGIC1, edit[j].bcolor);
- fl_set_call_back(bedit[j], edit_cb, j);
- x += dx;
- j++;
- }
-
- if (j < totaledit)
- {
- bedit[j] = fl_add_button(FL_NB, x, y, dx, dy, edit[j].name);
- fl_set_object_lsize(bedit[j], 10.0);
- fl_set_object_color(bedit[j], FL_MAGIC1, edit[j].bcolor);
- fl_set_call_back(bedit[j], edit_cb, j);
- j++;
- }
- }
-
- maxshown = j;
- obj = fl_add_button(FL_NB, 45.0, 160.0, 155.0, 22.0, "");
- fl_set_object_boxtype(obj, FL_RSHADOW_BOX);
- fl_set_object_lcol(obj, FL_BLUE);
- fl_set_object_lsize(obj, 10.00);
- fl_set_object_color(obj, FL_MAGIC1, FL_GREEN);
- fl_set_object_lstyle(obj, FL_BOLD_STYLE);
- if (totaledit > maxshown)
- {
- fl_set_object_label(obj, "More Edit Functions");
- fl_set_call_back(obj, up_dn_cb, 0);
- }
- else
- {
- fl_set_object_label(obj, "Edit Functions");
- fl_deactivate_object(obj);
- }
- fl_end_group();
-
- /* Type conversion group */
- cgrp = fl_bgn_group();
- obj = fl_add_box(FL_SHADOW_BOX, 240.0, 10.0, 95.0, 180.0, "");
- fl_set_object_color(obj, 49, 47);
- obj = fl_add_text(FL_NORMAL_TEXT, 245.0, 170.0, 95.0, 15.0, "ImageTypes");
- fl_set_object_lcol(obj, 4);
- fl_set_object_lsize(obj, 10.000);
- fl_set_object_align(obj, FL_ALIGN_CENTER);
- fl_set_object_lstyle(obj, FL_ITALIC_STYLE);
-
- x = 245;
- y = 135;
- for (dx = 85, dy = 25, i = 0; i < totalct; i++, y -= dy)
- {
- obj = fl_add_button(FL_NORMAL_BUTTON, x, y, dx, dy, ct[i].lab);
- fl_set_object_lsize(obj, 10.00);
- fl_set_object_color(obj, FL_MAGIC1, FL_YELLOW);
- fl_set_call_back(obj, type_cb, i);
- }
-
- fl_end_group();
-
- /* External group */
- exgrp = fl_bgn_group();
- obj = fl_add_box(FL_SHADOW_BOX, 250.0, 205.0, 80.0, 120.0, "");
- fl_set_object_color(obj, 49, 47);
- obj = fl_add_text(FL_NORMAL_TEXT, 250.0, 305.0, 80.0, 15.0, "ExtBinding");
- fl_set_object_lcol(obj, 4);
- fl_set_object_lsize(obj, 10.000);
- fl_set_object_align(obj, FL_ALIGN_CENTER);
- fl_set_object_lstyle(obj, FL_BOLD_STYLE);
-
- obj = fl_add_button(FL_NB, 258.0, 235.0, 65.0, 25.0, "Filter");
- fl_set_object_lsize(obj, 10.00);
- fl_set_call_back(obj, ext_cb, EXT_FILTER);
- obj = fl_add_button(FL_NB, 258.0, 265.0, 65.0, 25.0, "Convolve");
- fl_set_object_lsize(obj, 10.00);
- fl_set_call_back(obj, ext_cb, EXT_CONVOLV);
- fl_end_group();
-
- /* Pan groups */
- pgrp = fl_bgn_group();
- obj = fl_add_box(FL_SHADOW_BOX, 10.0, 195.0, 130.0, 130.0, "");
- fl_set_object_color(obj, 49, 47);
-
- x = x0 = 30.0;
- y = 220;
- for (dx = dy = 30, i = 1; i < 10; i += 3, y += dy, x = x0)
- {
- for (j = 0; j < 3; j++, x += dx)
- {
- if ((i + j) == 5)
- strcpy(lp, "@#circle");
- else
- sprintf(lp, "@#%d", (i + j));
- obj = fl_add_button(FL_TOUCH_BUTTON, x, y, dx, dy, lp);
- fl_set_object_color(obj, 47, 3);
- fl_set_object_lcol(obj, 1);
- fl_set_call_back(obj, pan_cb, (i + j));
- }
- }
-
- pspeed = fl_add_counter(FL_NC, 15.0, 200.0, 120.0, 20.0, "");
- fl_set_object_lsize(pspeed, FL_SMALL_FONT);
- fl_set_object_lstyle(pspeed, FL_BOLD_STYLE);
- fl_set_counter_precision(pspeed, 0);
- fl_set_counter_bounds(pspeed, 0.0, 200.0);
- fl_set_counter_step(pspeed, 1, 10);
- fl_set_counter_value(pspeed, 50.0);
- fl_end_group();
-
- /* brief info about current file */
- etitle = fl_add_button(FL_NB, 15.0, 335.0, 320.0, 25.0, "None");
- fl_set_object_boxtype(etitle, FL_FRAME_BOX);
- fl_set_object_color(etitle, FL_MAGIC1, FL_GREEN);
- fl_set_object_lsize(etitle, 10.000);
- fl_set_object_align(etitle, FL_ALIGN_CENTER);
- fl_set_call_back(etitle, special_cb, 0);
-
- /* Misc control */
- mgrp = fl_bgn_group();
- obj = fl_add_box(FL_SHADOW_BOX, 150.0, 195.0, 85.0, 130.0, "");
- fl_set_object_color(obj, 49, 47);
- obj = fl_add_text(FL_NT, 155.0, 305.0, 80.0, 15.0, "Misc. Cntl");
- fl_set_object_lcol(obj, 4);
- fl_set_object_lsize(obj, 10.000);
- fl_set_object_align(obj, FL_ALIGN_CENTER);
- fl_set_object_lstyle(obj, FL_BOLD_STYLE);
-
- x = 158;
- y = 280;
- for (dx = 69, dy = 20, i = 0; i < totalmisc; i++, y -= dy)
- {
- obj = fl_add_button(FL_NB, x, y, dx, dy, misccn[i].lab);
- fl_set_object_color(obj, 47, misccn[i].bcol);
- fl_set_object_boxtype(obj, FL_BORDER_BOX);
- fl_set_object_lsize(obj, 10.00);
- fl_set_call_back(obj, misc_cb, misccn[i].cbi);
- fl_set_button_shortcut(obj, misccn[i].scut);
- }
-
- fl_end_group();
- fl_end_form();
- }
-
-
- static void
- create_form_info(void)
- {
- FL_OBJECT *obj;
- int i, j;
- float x, y, dx, dy, x0;
-
- info = fl_bgn_form(FL_NO_BOX, 260.0, 268.0);
- obj = fl_add_box(FL_UP_BOX, 0.0, 0.0, 260.0, 268.0, "");
- fl_set_object_color(obj, 12, 47);
- obj = fl_add_button(FL_HB, 0.0, 0.0, 260, 268.0, "");
- fl_set_call_back(obj, version_cb, 0);
-
- /* Reportint group */
- infog = fl_bgn_group();
- obj = fl_add_box(FL_FRAME_BOX, 100.0, 85.0, 150.0, 130.0, "");
- fl_set_object_color(obj, 9, 47);
- obj = fl_add_text(FL_NT, 110.0, 195.0, 140.0, 15.0, "CurrentFile");
- fl_set_object_lcol(obj, 4);
- fl_set_object_lsize(obj, 10.000);
- fl_set_object_align(obj, FL_ALIGN_CENTER);
- fl_set_object_lstyle(obj, FL_BOLD_STYLE);
-
- x = 105.0;
- y = 170.0;
- for (dx = 140, dy = 20, i = 0; i < 5; y -= dy, i++)
- {
- freport[i] = fl_add_text(FL_NORMAL_TEXT, x, y, dx, dy, "");
- fl_set_object_boxtype(freport[i], FL_FRAME_BOX);
- fl_set_object_lsize(freport[i], 10.0);
- fl_set_object_align(freport[i], FL_ALIGN_CENTER);
- }
- fl_set_object_label(freport[0], "None");
- /* add a hidden button to shown more info */
- obj = fl_add_button(FL_HIDDEN_BUTTON, 100, 85, 150, 130, "");
- fl_set_call_back(obj, show_image_info, 0);
- fl_end_group();
-
-
- /* progress report group */
- fl_bgn_group();
- pslider = fl_add_valslider(FL_HFS, 10.0, 40.0, 240.0, 25.0, "");
- fl_set_object_color(pslider, 12, 3);
- fl_set_object_lsize(pslider, 10.000);
- fl_set_object_lstyle(pslider, FL_BOLD_STYLE);
- fl_set_slider_precision(pslider, 2);
- fl_set_slider_value(pslider, 0.0);
- fl_set_slider_bounds(pslider, 0.0, 1.0);
- pslider->active = 0;
-
- ptext = fl_add_text(FL_NORMAL_TEXT, 10.0, 65.0, 240.0, 20.0, "");
- fl_set_object_boxtype(ptext, FL_FLAT_BOX);
- fl_set_object_color(ptext, 12, 12);
- fl_set_object_lsize(ptext, 10.000);
- fl_set_object_align(ptext, FL_ALIGN_CENTER);
- fl_set_object_lstyle(ptext, FL_BOLD_STYLE);
- fl_end_group();
-
-
- /* misc reporting group */
- mrptg = fl_bgn_group();
- x = x0 = 10.0;
- for (y = 60, dx = 120, dy = 20, i = 0; i < 4; i += 2, y -= dy + 1, x = x0)
- {
- for (j = 0; j < 2; j++, x += dx + 1)
- {
- mreport[i + j] = fl_add_text(FL_NT, x, y, dx, dy, "");
- fl_set_object_boxtype(mreport[i + j], FL_BORDER_BOX);
- fl_set_object_lsize(mreport[i + j], 10.000);
- }
- }
- fl_end_group();
-
- /* File I/O */
-
- obj = fl_add_box(FL_SHADOW_BOX, 10.0, 90.0, 80.0, 125.0, "");
- fl_set_object_color(obj, 49, 47);
- obj = fl_add_text(FL_NT, 15.0, 195.0, 70.0, 15.0, "File I/O");
- fl_set_object_lcol(obj, 4);
- fl_set_object_lsize(obj, 10.000);
- fl_set_object_align(obj, FL_ALIGN_CENTER);
- fl_set_object_lstyle(obj, FL_BOLD_STYLE);
-
- iogroup = fl_bgn_group();
- x = 15;
- y = 170.0;
- for (dx = 70, dy = 20, i = 0; i < totalfio - 1; y -= (dy + 4), i++)
- {
- obj = fl_add_button(FL_NORMAL_BUTTON, x, y, dx, dy, fiob[i].lab);
- fl_set_object_boxtype(obj, FL_RSHADOW_BOX);
- fl_set_object_color(obj, 47, 12);
- fl_set_object_lsize(obj, 10.000);
- fl_set_call_back(obj, file_cb, fiob[i].cbi);
- fl_set_button_shortcut(obj, fiob[i].scut);
- }
- fl_end_group();
-
- /* the quit button */
- obj = fl_add_button(FL_NORMAL_BUTTON, x, y, dx, dy, fiob[i].lab);
- fl_set_object_boxtype(obj, FL_RSHADOW_BOX);
- fl_set_object_color(obj, 47, 12);
- fl_set_object_lsize(obj, 10.000);
- fl_set_call_back(obj, file_cb, fiob[i].cbi);
- fl_set_button_shortcut(obj, fiob[i].scut);
-
-
- /* misc control groups */
- fl_bgn_group();
-
- x = 10.0;
- for (y = 10, dx = 80, dy = 25, i = 0; i < totalimisc; i++, x += dx)
- {
- obj = fl_add_button(FL_NB, x, y, dx, dy, imisccn[i].lab);
- fl_set_object_lsize(obj, 10.00);
- fl_set_object_color(obj, FL_MAGIC1, imisccn[i].c);
- fl_set_call_back(obj, imisc_cb, i);
- }
- fl_end_group();
-
- obj = fl_add_button(FL_NB, 43.0, 222.0, 184.0, 30.0, rm_rcs_kw(sver));
- fl_set_object_boxtype(obj, FL_FRAME_BOX);
- fl_set_object_color(obj, 12, FL_GREEN);
- fl_set_object_lcol(obj, FL_BLUE);
- fl_set_object_lstyle(obj, FL_BOLD_STYLE);
- fl_set_object_lsize(obj, 11.0);
- fl_set_call_back(obj, version_cb, 0);
-
- fl_end_form();
- fl_scale_form(info, 1.04, 1.04);
- }
-
- static void
- create_forms(void)
- {
- static int ok;
- if (!ok)
- {
- create_form_cntl();
- create_form_info();
- ok = 1;
- }
- }
-